package basic.thread.again;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 使用AtomicInteger
 *
 * @author bingo
 * @create 2018-02-24 14:14
 **/
public class Squence2 {


    private AtomicInteger value = new AtomicInteger(0);

    public  int getValue(){
        return  value.getAndIncrement();

    }

    public static void main(String[] args) {
        Squence2 sequence2 = new Squence2();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"--"+sequence2.getValue());
                }

            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"--"+sequence2.getValue());
                }

            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"--"+sequence2.getValue());
                }

            }
        }).start();
    }
}
